package com.lalnou3g.hm0419;

import java.io.*;
import java.util.ArrayList;

/**
 * Created by dllo on 18/4/18.
 */
public class Main {
    public static void main(String[] args) {

        ArrayList<File> txtFiles = new ArrayList<>();
        //遍历文件夹
        new Thread(new Runnable() {
            @Override
            public void run() {
                File file = new File("Q1");
                File[] files = file.listFiles();
                for (File file1 : files) {
                    if (file1.toString().endsWith("txt")){
                        txtFiles.add(file1);
                    }
                }
            }
        }).start();



        // 删除 '//' 行
        new Thread(new Runnable() {
            @Override
            public void run() {
                for (File newFile : txtFiles) {
                    String tempName = newFile.getName().substring(0,1);

                    BufferedReader reader = null;
                    PrintWriter pw = null;
                    try {
                        reader = new BufferedReader(new InputStreamReader(new FileInputStream(newFile)));
                        pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("Q1"+File.separator+tempName+"-new.txt")));
                        String line = "";
                        while ((line = reader.readLine()) != null){

                            if (!line.startsWith("//")){
                                pw.println(line);
                            }
                        }
                        pw.flush();

                    } catch (Exception e) {
                        e.printStackTrace();
                    }finally {
                        IOUtils.closeAll(reader,pw);
                    }

                }



            }
        }).start();




    }

}
